<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>个人资料</title>
    <link rel="stylesheet" href="../css/newAdd.css">
    <script src="../js/jquery.js"></script>
    <script src="../js/myAjax.js"></script>
    <script src="../layui/layui.js"></script>
    <link rel="stylesheet" href="../layui/css/layui.css">
    <script src="../js/personal.js"></script>
</head>
<body style="display: flex;justify-content: center;background-color: ivory">
<div class="layui-form" style="width: 500px;margin-top: 100px">
    <div type="hidden" id="user-name"></div>
    <div class="layui-form-item">
        <label class="layui-form-label">用户名</label>
        <div class="layui-input-block">
            <input type="text" name="username" id="username" readonly required    autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">姓名</label>
        <div class="layui-input-block">
            <input type="text" name="name" id="name" required  lay-verify="required" placeholder="请输入您的姓名(待补充)" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">年龄</label>
        <div class="layui-input-block">
            <input type="text" name="age" id="age" required  lay-verify="required" placeholder="请输入年龄(待补充)" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">性别</label>
        <div class="layui-input-block">
            <input type="radio" name="sex" value="男" title="男">
            <input type="radio" name="sex" value="女" title="女">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">电话</label>
        <div class="layui-input-block">
            <input type="text" name="phone" id="phone" required  lay-verify="required" placeholder="请输入电话(待补充)" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">住址</label>
        <div class="layui-input-block">
            <input type="text" name="address" id="address" required  lay-verify="required" placeholder="请输入住址(待补充)" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">就读院校</label>
        <div class="layui-input-block">
            <select name="university" id="university" lay-verify="required" lay-search>

            </select>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">学历等级</label>
        <div class="layui-input-block">
            <select name="education" id="education" lay-verify="required" lay-search>

            </select>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">激活</label>
        <div class="layui-input-block">
            <input type="checkbox" value="1" name="switch" lay-skin="switch">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">注册时间</label>
        <div class="layui-input-block">
            <input type="text" name="registerTime" id="registerTime" readonly  autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn" lay-submit lay-filter="formDemo">确认修改</button>
            <button type="reset" onclick="reseta()" class="layui-btn layui-btn-primary" style="width: 100px">重置</button>
        </div>
    </div>
</div>

<script>
    //Demo
    layui.use('form', function(){
        var form = layui.form;

        //监听提交
        form.on('submit(formDemo)', function(){
            // layer.msg(JSON.stringify(data.field));
            let data = {
               username:$("#username").val(),
                name:$("#name").val(),
                age:$("#age").val(),
                sex:$('input[name="sex"]:checked').val(),
                phone:$("#phone").val(),
                address: $("#address").val(),
                education:$("#education").find("option:selected").text(),
                graduate:$("#university").find("option:selected").text(),
                registrationTime:$("#registerTime").val(),
                state:$('input:checkbox[name="switch"]:checked').val(),
            }
            console.log(data);
            let result = myAjax('/user/edit','post',data);
            if (result===1){
                layer.msg("修改成功");
            }else {
                layer.msg("系统繁忙！请稍后再试！");
            }
            return false;
        });
    });
    function reseta() {
      location.assign("/html/personal_data.html")
    }
</script>

</body>
</html>